// -------------
// --- timer ---
// -------------

#include <avr/io.h>
//#include <avr/interrupt.h>

// the values are calculated with AvrWiz for ATmega328P @ 20 mhz
// Timer1 settings: 2000000 ticks (= 100 ms)
// !!! warning !!! real ticks = 0 (= 0 us), err = 100% !!!
// (seconds error per day = 8640)

// Timer1 Overflow
ISR(TIMER1_OVF_vect)
{
	// reinit counter
	TCNT1H = 0;
	TCNT1L = 0;
}

// Timer1 Capture
ISR(TIMER1_CAPT_vect)
{
}

// Timer1 Compare A
ISR(TIMER1_COMPA_vect)
{
}

// Timer1 Compare B
ISR(TIMER1_COMPB_vect)
{
}

void Timer1_init()
{
	// Timer1 settings: ~ 0 ticks (0 us)
	TCCR1B = 0; // prescaler = 0
	// init counter
	TCNT1H = 0;
	TCNT1L = 0;
	TIMSK1 = (1<<TOIE1); // Timer1 Overflow Interrupt Enable
//TODO: enable irq: capt
//TODO: enable irq: compa
//TODO: enable irq: compb
}

void init_timer()
{
	Timer1_init();
}

//+++++++++++++++++++++++++Atmega32+++++++++++++++++++
// -------------
// --- timer ---
// -------------

#include <avr/io.h>
//#include <avr/interrupt.h>

// the values are calculated with AvrWiz for ATmega32 @ 16 mhz
// Timer1 settings: 1600000 ticks (= 100 ms)

// Timer1 Overflow
ISR(TIMER1_OVF_vect)
{
	// reinit counter
	TCNT1H = 158;
	TCNT1L = 88;
}

// Timer1 Capture
ISR(TIMER1_CAPT_vect)
{
}

// Timer1 Compare A
ISR(TIMER1_COMPA_vect)
{
}

// Timer1 Compare B
ISR(TIMER1_COMPB_vect)
{
}

void Timer1_init()
{
	// Timer1 settings: ~ 1600000 ticks (100 ms)
	TCCR1B = (1<<CS11) | (1<<CS10); // prescaler = 64
	// init counter
	TCNT1H = 158;
	TCNT1L = 88;
	TIMSK = (1<<TOIE1); // Timer1 Overflow Interrupt Enable
//TODO: enable irq: capt
//TODO: enable irq: compa
//TODO: enable irq: compb
}

void init_timer()
{
	Timer1_init();
}



// generated by AvrWiz on 10/31/2011 9:57:01 PM

